package com.lzq.badminton.controller;

import com.lzq.badminton.dto.LoginDto;
import com.lzq.badminton.service.UserAdminService;
import com.lzq.badminton.vo.ResponseResult;
import com.lzq.badminton.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserAdminController {

    @Autowired
    private UserAdminService userAdminService;


    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginDto loginDto){
        return ResponseResult.okResult(userAdminService.login(loginDto));
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody LoginDto loginDto){
        userAdminService.register(loginDto);
        return ResponseResult.okResult();
    }

    @GetMapping("/info")
    public ResponseResult getUserInfo(@RequestParam String token){
        UserInfoVo userInfoVo = userAdminService.getUserInfo(token);
        return ResponseResult.okResult(userInfoVo);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return ResponseResult.okResult();
    }

}
